//
// Created by wwl on 2021/12/8.
//
#include  <stdio.h>
#include <time.h>

struct clock {
    int hour;
    int minute;
    int second;
};
typedef struct clock CLOCK;
void Update(CLOCK *cl) {
    cl->second++;
    if (cl->second == 60) {
        cl->second = 0;
        cl->minute++;
    }
    if (cl->minute == 60) {
        cl->minute = 0;
        cl->hour++;
    }
    if (cl->hour == 24) {
        cl->hour = 0;
    }
}
void Display(CLOCK cl) {
    printf("%2d:%2d:%2d\r", cl.hour, cl.minute, cl.second);
}
void Delay(void) {
    long t;
    for (t = 0; t < 400000000; t++) {
    }
}
int ClockMain() {
    CLOCK cl;
    long i;
    time_t rawTime;
    time(&rawTime);
    struct tm *timeInfo = localtime(&rawTime);

    cl.hour= timeInfo->tm_hour;    /*hour,minute,second赋初值*/
    cl.minute = timeInfo->tm_min;
    cl.second = timeInfo->tm_sec;
    for (i = 0; i < 400000000; i++)    /*利用循环结构，控制时钟运行的时间*/
    {
        Update(&cl);                    /*时钟更新*/
        Display(cl);                    /*时间显示*/
        Delay();                    /*模拟延时1秒*/
    }
}
